﻿#region Header

/*
    This file is part of ndoctor-statistics.

    ndoctor-statistics is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    ndoctor-statistics is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with ndoctor-statistics.  If not, see <http://www.gnu.org/licenses/>.
*/

#endregion Header

namespace Probel.NDoctor.Statistics.Helpers
{
    using System;
    using System.Collections.Generic;

    using Probel.NDoctor.Statistics.Domain;

    internal static class EntityExtensions
    {
        #region Methods

        public static void NormaliseToLocal(this SessionDuration @this)
        {
            @this.TimeStamp = DateTime.SpecifyKind(@this.TimeStamp, DateTimeKind.Local);
        }

        public static void NormaliseToLocal(this StatisticEntry @this)
        {
            @this.TimeStamp = DateTime.SpecifyKind(@this.TimeStamp, DateTimeKind.Local);
        }

        public static void NormaliseToLocal(this Application @this)
        {
            @this.InstallationDate = DateTime.SpecifyKind(@this.InstallationDate, DateTimeKind.Local);
            @this.LastUpdate = DateTime.SpecifyKind(@this.LastUpdate, DateTimeKind.Local);
        }

        public static void NormaliseToLocal(this IEnumerable<StatisticEntry> items)
        {
            items.ForEach(e => e.NormaliseToLocal());
        }

        public static void NormaliseToLocal(this IEnumerable<Application> items)
        {
            items.ForEach(e => e.NormaliseToLocal());
        }

        public static void NormaliseToLocal(this IEnumerable<SessionDuration> items)
        {
            items.ForEach(e => e.NormaliseToLocal());
        }

        public static void ToUtc(this SessionDuration @this)
        {
            @this.TimeStamp = @this.TimeStamp.ToUniversalTime();
        }

        public static void ToUtc(this StatisticEntry @this)
        {
            @this.TimeStamp = @this.TimeStamp.ToUniversalTime();
        }

        public static void ToUtc(this Application @this)
        {
            @this.InstallationDate = @this.InstallationDate.ToUniversalTime();
            @this.LastUpdate = @this.LastUpdate.ToUniversalTime();
        }

        public static void ToUtc(this IEnumerable<StatisticEntry> items)
        {
            items.ForEach(e => e.ToUtc());
        }

        public static void ToUtc(this IEnumerable<Application> items)
        {
            items.ForEach(e => e.ToUtc());
        }

        public static void ToUtc(this IEnumerable<SessionDuration> items)
        {
            items.ForEach(e => e.ToUtc());
        }

        #endregion Methods
    }
}